package com.zmc.lostfound.system.controller;

import com.zmc.lostfound.common.utils.PageParams;
import com.zmc.lostfound.common.utils.PageResult;
import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import com.zmc.lostfound.system.entity.FunctionEntity;
import com.zmc.lostfound.system.vo.FunctionSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.zmc.lostfound.system.service.FunctionService;

import java.util.List;

/**
 * @author LJQ
 * description 系统功能信息管理接口
 */
@RestController
@RequestMapping("/function")
@Api(value = "系统功能信息管理接口", tags = "系统功能信息管理接口")
public class FunctionController {

    private final FunctionService functionService;

    public FunctionController(FunctionService functionService) {
        this.functionService = functionService;
    }

    @ApiOperation("分页模糊查询系统功能信息")
    @PostMapping("/query/page")
    public Result queryPage(@RequestBody @Validated PageParams pageParams) {
        PageResult pageResult = functionService.queryPage(pageParams);
        return Result.ok("查询成功").put("pageResult", pageResult);
    }

    @ApiOperation("查询全部系统功能信息")
    @GetMapping("/query/all")
    public Result queryAll() {
        List<FunctionEntity> functionInfoList = functionService.findAll();
        return Result.ok("查询成功").put("functionInfoList", functionInfoList);
    }

    @ApiOperation("按主键id查询系统功能信息")
    @GetMapping("/query/info/{id}")
    public Result queryInfoById(@PathVariable("id") Long id) {
        FunctionEntity functionInfo = functionService.queryInfoById(id);
        return Result.ok("查询成功").put("functionInfo", functionInfo);
    }

    @ApiOperation("新增系统功能信息")
    @PostMapping("/insertFunction")
    public Result insertFunction(@RequestBody @Validated(value = {AddGroup.class}) FunctionSaveVO functionSaveVO) {
        return functionService.insertFunction(functionSaveVO);
    }

    @ApiOperation("修改系统功能信息")
    @PutMapping("/updateFunction")
    public Result updateFunction(@RequestBody @Validated(value = {UpdateGroup.class}) FunctionSaveVO functionSaveVO) {
        return functionService.updateFunction(functionSaveVO);
    }

    @ApiOperation("按功能id删除系统功能信息")
    @DeleteMapping("/delete/{functionId}")
    public Result deleteByFunctionId(@PathVariable("functionId") Long functionId) {
        return functionService.deleteByFunctionId(functionId);
    }

}
